package com.example.myapplication.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.myapplication.R;


public class ProfileFragment extends Fragment {
    private TextView todayPoints;
    private TextView totalPoints;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);
        initViews(view);
        setupClickListeners(view);
        return view;
    }

    private void initViews(View view) {
        todayPoints = view.findViewById(R.id.today_points);
        totalPoints = view.findViewById(R.id.total_points);

        // 设置积分数据
        todayPoints.setText("50");
        totalPoints.setText("1280");
    }

    private void setupClickListeners(View view) {
        // 学习记录
        LinearLayout questionSet = view.findViewById(R.id.layout_question_set);
        LinearLayout collection = view.findViewById(R.id.layout_collection);
        LinearLayout message = view.findViewById(R.id.layout_message);
        LinearLayout practice = view.findViewById(R.id.layout_practice);

        // 积分工具
        LinearLayout shoppingCart = view.findViewById(R.id.layout_shopping_cart);
        LinearLayout order = view.findViewById(R.id.layout_order);

        // 更多
        LinearLayout logout = view.findViewById(R.id.layout_logout);

        questionSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("问题集");
            }
        });

        collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("收藏");
            }
        });

        message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("消息");
            }
        });

        practice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("我的实践");
            }
        });

        shoppingCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("购物车");
            }
        });

        order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("订单");
            }
        });

        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("退出登录");
            }
        });
    }

    private void showToast(String message) {
        Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
    }
}